﻿#region Includes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace GingerGL.Graphics
{
    //------------------------------------------------------------//
    /// <summary>
    /// Stores Vertex, and Index Buffers
    /// </summary>
    public class GeometryBuffer : IDisposable
    {
        //--------------------------------------------------------//
        #region Properties
        /// <summary>
        /// Gets Vertex Buffer
        /// </summary>
        public VertexBuffer VertexBuffer { get; private set; }
        /// <summary>
        /// Gets Index Buffer
        /// </summary>
        public IndexBuffer IndexBuffer { get; private set; }
        /// <summary>
        /// Gets TRUE if Buffers are Commited to Video Memory
        /// </summary>
        public bool IsCommited { get { return VertexBuffer.IsCommited && IndexBuffer.IsCommited; } }
        #endregion
        //--------------------------------------------------------//
        #region Constructors
        /// <summary>
        /// Initializes a new instance of object
        /// </summary>
        public GeometryBuffer()
        {
            // Init private members
            this.VertexBuffer = new VertexBuffer();
            this.IndexBuffer = new IndexBuffer();
        }
        /// <summary>
        /// Initializes a new instance of object
        /// </summary>
        public GeometryBuffer(VertexBuffer vb, IndexBuffer ib)
        {
            this.IndexBuffer = ib;
            this.VertexBuffer = vb;
        }
        #endregion
        //--------------------------------------------------------//
        #region Methods
        /// <summary>
        /// Commit Buffers to Video Memory
        /// </summary>
        public void Commit() { IndexBuffer.Commit(); VertexBuffer.Commit(); }
        /// <summary>
        /// Clears Local Cache
        /// </summary>
        public void Clear() { IndexBuffer.Clear(); VertexBuffer.Clear(); }
        /// <summary>
        /// Decommits the Buffers from Video Memory
        /// </summary>
        public void Invalidate() { IndexBuffer.Invalidate(); VertexBuffer.Invalidate(); }
        /// <summary>
        /// Disposes of this class and video memory
        /// </summary>
        public void Dispose() 
        { 
            IndexBuffer.Dispose();  IndexBuffer = null;
            VertexBuffer.Dispose(); VertexBuffer = null;
        }
        #endregion
        //--------------------------------------------------------//
    }
    //------------------------------------------------------------//
}
